<?php
$servername = 'localhost';
$username = 'username';
$password = 'password';
$dbname = 'myDB';

$connect = mysqli_connect($servername, $username, $password, $dbname);

if (!$connect) {
    die ('连接失败' . mysqli_connect_error());
}
// 设置 SQL 语句从 MyGuests 数据表中读取 id, firstname 和 lastname 三个字段
$sql = "SELECT id, firstname, lastname, email FROM MyGuests";
// 调用 mysqli_query 从数据库中读取数据集并赋给变量 $result
$result = mysqli_query($connect, $sql);
// 调用 mysqli_num_rows 判断返回的数据是否为空数据
if (mysqli_num_rows($result) > 0) {
    // 调用 mysqli_fetch_assoc() 将结合集放入到关联数组并循环输出
    while ($row = mysqli_fetch_assoc($result)) {
        echo 'id: ' . $row["id"] . ' - Name: ' . $row["firstname"] . ' ' . $row["lastname"] . ' - Email: ' . $row["email"] . "<br />";
    }
} else {
    echo '0 结果';
}

mysqli_close($connect);
?>